package net.tycmc.cty.ctyms.web.Action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.tycmc.bulb.dbutil.global.GlobalThreadParam;
import net.tycmc.cty.ctyms.timejob.iems.service.VclRoadInfoService;

public class MaexecuteVclRoadAction extends BaseActionS2 {

	private VclRoadInfoService vclRoadInfoService;

	public VclRoadInfoService getVclRoadInfoService() {
		return vclRoadInfoService;
	}

	public void setVclRoadInfoService(VclRoadInfoService vclRoadInfoService) {
		this.vclRoadInfoService = vclRoadInfoService;
	}
	public String init(){
		return "MaexecuteVclRoadInit";
	}
	//执行统计作业
	public void executeVclRoad() throws IOException{
		Map<String,Object> param = new HashMap<String, Object>();
		PrintWriter out = response.getWriter();
		String workDay = request.getParameter("workDay");
		GlobalThreadParam.vclRoadDay=workDay;
		String dataBaseIp = request.getParameter("dataBaseIp");
		String user = request.getParameter("user");
		String password = request.getParameter("password");
		String MsgTDataBase = request.getParameter("MsgTDataBase");
		String MsgPDataBase = request.getParameter("MsgPDataBase");
		String databaseVclView = request.getParameter("databaseVclView");
		String VclViewDataBase = request.getParameter("VclViewDataBase");
		param.put("workDay", workDay);
		param.put("dataBaseIp", dataBaseIp);
		param.put("user", user);
		param.put("password", password);
		param.put("MsgTDataBase", MsgTDataBase);
		param.put("MsgPDataBase", MsgPDataBase);
		param.put("databaseVclView", databaseVclView);
		param.put("VclViewDataBase", VclViewDataBase);
		//调用service方法执行统计祖业
		vclRoadInfoService.runRoadExecutorService(param);
		out.print("<script language='javascript'>");
		out.print("alert('道路信息统计作业开始执行！请耐心等待！不要重复操作');");
		out.print("</script>");
		
	}
	public void getVclRoadHistoryCount() throws IOException{
		PrintWriter out = response.getWriter();
		List<Map<String,Object>> list = vclRoadInfoService.getVclRoadCount();
		String isExectue = GlobalThreadParam.vclRoadDay;
		int exeCount = 0;
		String exeThread = "0";
		if(isExectue!=null){
			exeCount=vclRoadInfoService.getExecuteCount(isExectue);
			exeThread="1";
		}
		String value="";
		for(Map<String,Object> map : list){
			value += map.get("workday")+":"+map.get("cont")+",";
		}
		value = value.substring(0, value.length()-1);
		out.print("{'value':'"+value + "','exeThread':'"+exeThread+"','exeCount':'"+exeCount+"','day':'"+isExectue+"'}");
	}
}
